//
//  ChangeController.m
//  EagleEye
//
//  Created by 18_李明明 on 15-1-22.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "ChangeController.h"

@interface ChangeController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *changeTableView;
@property (nonatomic, strong) NSMutableArray *array;
@end

@implementation ChangeController
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.array = [NSMutableArray array];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    // 创建tablevew
    self.changeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, WIDTH, HEIGHT - 60) style:UITableViewStyleGrouped];
    self.changeTableView.delegate = self;
    self.changeTableView.dataSource = self;
    [self.view addSubview:self.changeTableView];
    for (NSDictionary *tempDic in self.changeDetail) {
        [self.array addObject:[tempDic objectForKey:@"line_name"]];
        [self.array addObject:[tempDic objectForKey:@"start_stat"]];
        [self.array addObject:[tempDic objectForKey:@"end_stat"]];
    }
    // 添加一个返回的按钮
    UIButton *cancle = [UIButton buttonWithType:UIButtonTypeSystem];
    cancle.frame = CGRectMake(0, HEIGHT - 40, 50, 40);
//    [cancle setTitle:@"返回" forState:UIControlStateNormal];
    [cancle setBackgroundImage:[UIImage imageNamed:@"cancle.png"] forState:UIControlStateNormal];
    [self.view addSubview:cancle];
    [cancle addTarget:self action:@selector(targetCancle:) forControlEvents:UIControlEventTouchUpInside];
}
// 返回按钮方法
- (void)targetCancle:(UIButton *)cancle
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"0502"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"0502"];
    }
    NSLog(@"%@", [self.array objectAtIndex:indexPath.row]);
    cell.textLabel.text = [self.array objectAtIndex:indexPath.row];
    cell.textLabel.numberOfLines = 0;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([[self.array objectAtIndex:indexPath.row] length] >17) {
        return 66;
    }
    return 44;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"换乘路径";
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
